<template>
  <div class="containers">
    <div class="container">
      <div class="form-box" style="width: 100%;max-width: 900px;">
        <el-tabs>
          <!-- <el-tab-pane label="释放设置">
            <el-form ref="form" label-width="120px">
              <el-form-item label="释放">
                <el-input v-model="release">
                  <template slot="append">%</template>
                </el-input>
              </el-form-item>
              <el-form-item label="肯德基利润">
                <el-input v-model="kfc_profit">
                  <template slot="append">%</template>
                </el-input>
              </el-form-item>
              <span class="dialog-footer">
                <el-button type="prove" @click="setrel()">确 定</el-button>
              </span>
            </el-form>
          </el-tab-pane> -->
          <el-tab-pane label="物流设置">
            <el-form ref="form" label-width="120px">
              <el-form-item label="secretId">
                <el-input v-model="form.secretId"></el-input>
              </el-form-item>
              <el-form-item label="secretKey">
                <el-input v-model="form.secretKey"></el-input>
              </el-form-item>
              <el-form-item label="source">
                <el-input v-model="form.source"></el-input>
              </el-form-item>
              <el-form-item label="url">
                <el-input v-model="form.url"></el-input>
              </el-form-item>
              <span class="dialog-footer">
                <el-button type="prove" @click="setlv()">确 定</el-button>
              </span>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="七牛云设置">
            <el-form ref="updata" label-width="200px">
              <el-form-item label="空间名称">
                <el-input v-model="updata.bucket"></el-input>
              </el-form-item>
              <el-form-item label="secretKey">
                <el-input v-model="updata.secret"></el-input>
              </el-form-item>
              <el-form-item label="accessKey">
                <el-input v-model="updata.access"></el-input>
              </el-form-item>
              <el-form-item label="七牛云上传地址">
                <el-input v-model="updata.upload"></el-input>
              </el-form-item>
              <el-form-item label="图片会显地址">
                <el-input v-model="updata.url"></el-input>
              </el-form-item>
              <span class="dialog-footer">
                <el-button type="prove" @click="setlvs()">确 定</el-button>
              </span>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="短信设置">
            <el-form ref="updatas" label-width="200px">
              <el-form-item label="是否开启短信验证">
                <el-switch v-model="updatas.is_open" active-color="#13ce66" inactive-color="red">
                </el-switch>
              </el-form-item>
              <el-form-item label="短信验证码有效期">
                <el-input v-model="updatas.validity"></el-input>
              </el-form-item>
              <el-form-item label="分享码是否必填">
                <el-switch v-model="updatas.is_share" active-color="#13ce66" inactive-color="red">
                </el-switch>
              </el-form-item>
              <el-form-item label="短信平台">
                <el-select v-model="updatas.use" @change="setState" placeholder="请选择类型" size="small" class="mr10">
                  <el-option v-for="(item, index) in msglist" :key="item.key" :label="item.name" :value="item.key">
                  </el-option>
                </el-select>
              </el-form-item>
              <div v-if="updatas.use == 'yunxinshi'">
                <el-form-item label="平台账号">
                  <el-input v-model="updatas.yunxinshi.uid"></el-input>
                </el-form-item>
                <el-form-item label="平台密钥">
                  <el-input v-model="updatas.yunxinshi.pwd"></el-input>
                </el-form-item>
                <el-form-item label="平台名称">
                  <el-input v-model="updatas.yunxinshi.title"></el-input>
                </el-form-item>
              </div>
              <div v-if="updatas.use == 'ali'">
                <el-form-item label="阿里code">
                  <el-input v-model="updatas.ali.template_code"></el-input>
                </el-form-item>
                <el-form-item label="阿里id">
                  <el-input v-model="updatas.ali.access_key_id"></el-input>
                </el-form-item>
                <el-form-item label="阿里secret">
                  <el-input v-model="updatas.ali.access_key_secret"></el-input>
                </el-form-item>
                <el-form-item label="阿里名称">
                  <el-input v-model="updatas.ali.title"></el-input>
                </el-form-item>
              </div>


              <span class="dialog-footer">
                <el-button type="prove" @click="setlvss()">确 定</el-button>
              </span>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="实名认证设置">
            <el-form ref="forms" label-width="200px">

              <el-form-item label="实名认证平台">
                <el-input v-model="forms.use"></el-input>
              </el-form-item>
              <el-form-item label="阿里url">
                <el-input v-model="forms.ali.url"></el-input>
              </el-form-item>
              <el-form-item label="阿里appcode">
                <el-input v-model="forms.ali.appcode"></el-input>
              </el-form-item>
              <el-form-item label="阿里name_key">
                <el-input v-model="forms.ali.name_key"></el-input>
              </el-form-item>
              <el-form-item label="阿里card_key">
                <el-input v-model="forms.ali.card_key"></el-input>
              </el-form-item>
              <el-form-item label="阿里result">
                <el-input v-model="forms.ali.result"></el-input>
              </el-form-item>
              <el-form-item label="阿里result_message">
                <el-input v-model="forms.ali.result_message"></el-input>
              </el-form-item>
              <span class="dialog-footer">
                <el-button type="prove" @click="setlvsss()">确 定</el-button>
              </span>
            </el-form>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>
import { number } from 'echarts';


export default {


  data() {
    return {
      kfc_profit: 0,
      release: 0,
      code: 0,
      msglist: [{ name: '云信使', key: 'yunxinshi' }, { name: '阿里云', key: 'ali' }],
      form: {
        secretId: "",
        secretKey: "",
        source: "",
        url: "",
      },
      state: '',
      forms: {
        use: "",//平台
        ali: { url: '', appcode: '', name_key: '', card_key: "", result: "", result_message: "" },//阿里云官方密钥
      },
      updata: {
        bucket: "",
        secret: "",
        today_accelerate: "",
        upload: "",//上传
        url: "",//回显
      },
      updatas: {
        is_open: false,
        is_share: false,
        use: "",//短信平台
        validity: 0,//短信验证码有效期最短60秒
        yunxinshi: { uid: "", pwd: "", title: "" },//平台密钥
        ali: { template_code: '', access_key_id: '', access_key_secret: '', title: "" },//阿里云官方密钥
      }

    };
  },
  created() {
    this.load()//获取
  },
  methods: {
    setState() {

    },
    load() {
      this.request('admin/releaseSet/', 'get', {}).then(
        res => {
          if (res.errno == 0) {
            this.release = res.data.release
            this.kfc_profit = res.data.kfc_profit
          }
        },
        function () {
          console.log('请求失败处理');
        }
      );
      this.request('admin/logisticsSet/', 'get', {}).then(
        res => {
          if (res.errno == 0) {
            this.form = res.data
          }
        },
        function () {
          console.log('请求失败处理');
        }
      );
      this.request('admin/qiniuSet/', 'get', {}).then(
        res => {
          if (res.errno == 0) {
            this.updata = res.data
            console.log(res.data)
          }
        },
        function () {
          console.log('请求失败处理');
        }
      );
      this.request('admin/msgSet/', 'get', {}).then(
        res => {
          if (res.errno == 0) {
            this.updatas = res.data
            this.state = res.data.use
            console.log(res.data)
          }
        },
        function () {
          console.log('请求失败处理');
        }
      );
      this.request('admin/RealNameSet/', 'get', {}).then(
        res => {
          if (res.errno == 0) {
            this.forms = res.data
            console.log(res.data)
          }
        },
        function () {
          console.log('请求失败处理');
        }
      );

    },
    setlvsss() {
      // this.updatas.validity=Number(this.updatas.validity)
      this.request('admin/RealNameSet/', 'post', this.forms).then(
        res => {
          this.$message.success(res.errmsg)
        },
        function () {
          console.log('请求失败处理');
        }
      );
    },
    setlvss() {
      this.updatas.validity = Number(this.updatas.validity)
      this.request('admin/msgSet/', 'post', this.updatas).then(
        res => {
          this.$message.success(res.errmsg)
        },
        function () {
          console.log('请求失败处理');
        }
      );
    },
    setlvs() {
      this.request('admin/qiniuSet/', 'post', this.updata).then(
        res => {
          this.$message.success(res.errmsg)
        },
        function () {
          console.log('请求失败处理');
        }
      );
    },
    setlv() {
      this.request('admin/logisticsSet/', 'post', this.form).then(
        res => {
          this.$message.success(res.errmsg)
        },
        function () {
          console.log('请求失败处理');
        }
      );
    },
    //释放设置
    setrel() {
      this.request('admin/releaseSet/', 'post', { release: parseFloat(this.release), kfc_profit: parseFloat(this.kfc_profit) }).then(
        res => {
          this.$message.success(res.errmsg)
        },
        function () {
          console.log('请求失败处理');
        }
      );
    }




  }
};
</script>
<style scoped="scoped">
.container {
  padding: 20px;
}

.activeattr {
  border: 1px solid rgb(64, 158, 255);
  color: rgb(64, 158, 255);
}

.el-upload {
  width: 100px !important;
  height: 100px !important;
}
</style>
